import 'package:base_moudle/index.dart';

import '../../../../config/zs_routers.dart';
import '../../../../models/data_model/zs_work_notice_list_model.dart';
import '../../../../new_paltform/define/hy_header.dart';
import '../hy_work_home_logic.dart';

class HyNoticeCell extends StatelessWidget {
  HyNoticeCell({Key? key, required this.controller}) : super(key: key);

  HyWorkHomeLogic controller;

  @override
  Widget build(BuildContext context) {
    return HYContainer(
      padding: const EdgeInsets.only(left: 16, right: 16),
      backgroundColor: Colors.white,
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              ZsText(
                '通知公告',
                fontSize: 18,
                fontWeight: FontWeight.bold,
              ),
              _buildMoreWidget().intoGestureDetector(onTap: () {
                Get.toNamed(ZsRouter.zsWorkNoticeList)
                    ?.then((value) => controller.requestNotice());
              })
            ],
          ).marginOnly(top: 24),
          ClipRRect(
            borderRadius: BorderRadius.circular(12),
            child: Container(
              color: ColorHex('#3370FF'),
              padding: const EdgeInsets.all(1),
              child: HYContainer(
                backgroundColor: Colors.white,
                alignment: Alignment.center,
                clipBehavior: Clip.hardEdge,
                gradient: LinearGradient(
                    begin: Alignment.topCenter,
                    end: Alignment.bottomCenter,
                    colors: [ColorHex('#F0F5FD'), ColorHex('#FFFFFF')]),
                border: Border.all(color: Colors.transparent),
                borderRadius: const BorderRadius.all(Radius.circular(11)),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: _notifyListWidget(controller.noticeList),
                ),
                // child: Container(),
              ),
            ),
          ).marginOnly(top: 16),
        ],
      ),
    );
  }

  Widget _buildMoreWidget() {
    return Row(
      children: [
        ZsText(
          '查看更多',
          fontWeight: FontWeight.bold,
          color: ColorHex('#187AFF'),
        )
      ],
    );
  }

  List<Widget> _notifyListWidget(List<ZsWorkNoticeListModel> data) {
    final List<Widget> items = [];
    if (data.isEmpty) {
      items.add(Column(
        children: [
          Image.asset(
            'assets/images/empty_data.png',
            height: 200,
            fit: BoxFit.cover,
          ),
          ZsText(
            '暂无通知数据',
            textAlign: TextAlign.center,
            color: zs_color_ccc,
            bottom: 20,
          )
        ],
      ));
    }
    for (int i = 0; i < data.length; i++) {
      if (i > 2) {
        break;
      }
      items.add(Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              if (data[i].readTime == '')
                BoardText(
                  'NEW',
                  color: Colors.white,
                  backgroundColor: ColorHex('#FF5252'),
                  fontSize: 12,
                  left: 3,
                  right: 3,
                  top: 2,
                  bottom: 2,
                  borderRadius: BorderRadius.circular(2),
                ).marginOnly(right: 5).intoFlexible(),
              ZsText(
                data[i].title.toString(),
                color: ColorHex('#0C296E'),
                fontWeight: FontWeight.bold,
                fontSize: 16,
                top: 5,
                bottom: 5,
                maxLines: 1,
              ).intoFlexible(flex: 5)
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              ZsText(
                data[i].writer.toString(),
                color: ColorHex('#0C296E'),
                fontSize: 12,
              ).intoFlexible(flex: 2),
              ZsText(
                // data[i].issuetime.toString(),
                DateTime.fromMillisecondsSinceEpoch(
                        int.parse(data[i].issuetime.toString()))
                    .toString()
                    .substring(0, 10),
                color: ColorHex('#3370FF'),
                fontSize: 12,
              ),
            ],
          ).intoContainer(padding: const EdgeInsets.only(top: 5, bottom: 10))
        ],
      )
          .intoContainer(
              padding: const EdgeInsets.only(top: 10, left: 18, right: 18),
              decoration: BoxDecoration(
                  border:
                      Border(bottom: BorderSide(color: ColorHex('#F2F2F2')))))
          .intoGestureDetector(onTap: () {
        Get.toNamed(ZsRouter.zsWorkNoticeDetail, arguments: data[i].informid);
      }));
    }
    return items;
  }
}
